package com.hkfn.rfb.rfb.bean;

import com.hkfn.rfb.common.bean.BaseModel;
import com.hkfn.rfb.common.bean.ConstData;
import com.hkfn.rfb.common.utils.StringUtils;

import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.List;

import lombok.Data;
import lombok.EqualsAndHashCode;

/**
 * Rfb工单对象
 */
@Data
@EqualsAndHashCode(callSuper = true)
public class RfbProjectManageModel extends BaseModel {

    private long _id;
    private String projectName;
    /**
     * 项目类型 0项目类型1 1项目类型2 2项目类型3
     */
    private String projectType;

    private List<RfbDataModel> testObject;

    private long startTime;

    private long stopTime;

    private String clientName;

    /**
     * 负责人
     */
    private String startPerson;

    private String deviceInfo;

    private String projectStatus;

    private String projectDescription;

    private String testContent;

    private long completeTime;

    public RfbProjectManageModel() {
    }

    public RfbProjectManageModel(long _id) {
        this._id = _id;
    }

    public void generateData(){
        projectName = "项目" + (_id + 1);
        projectType = ""+(int)(Math.random() * 3);
        startTime = System.currentTimeMillis();
        stopTime = System.currentTimeMillis() + 1000 * 60 * 60 * 24 * 7;
        clientName = "委托单位";
        startPerson = "张三";
        deviceInfo = "测试设备";
        projectStatus =  ""+(int)(Math.random() * 3);
        switch (projectStatus){
            case "0":// 未开始
                startTime = System.currentTimeMillis() + 1000 * 60 * 60 * 24;
                stopTime = System.currentTimeMillis() + 1000 * 60 * 60 * 24 * 7;
                completeTime = 0;
                break;
            case "1":// 进行中
                startTime = System.currentTimeMillis() - 1000 * 60 * 60 * 24;
                stopTime = System.currentTimeMillis() + 1000 * 60 * 60 * 24 * 7;
                completeTime = 0;
                break;
            case "2":// 已完成
                startTime = System.currentTimeMillis() - 1000 * 60 * 60 * 24 * 7;
                stopTime = System.currentTimeMillis() - 1000 * 60 * 60 * 24;
                completeTime = stopTime;
                break;
        }
        projectDescription = "项目描述";
        testContent = "测试内容";
    }

    /**
     * 获取工单类型
     * @return
     */
    public String obtainTypeStr(){
        switch (projectType){
            case "0":
                return "项目类型1";
            case "1":
                return "项目类型2";
            default:
                return "项目类型3";
        }
    }

    /**
     * 获取工单类型
     * @return
     */
    public void setTypeStr(String typeStr){
        switch (typeStr){
            case "项目类型1":
                projectType = "0";
                break;
            case "项目类型2":
                projectType = "1";
                break;
            default:
                projectType = "2";
                break;
        }
    }

    public String obtainTestObjectStr(){
        if (null != testObject && testObject.size() > 0){
            StringBuilder stringBuilder = new StringBuilder();
            for (RfbDataModel rfbDataModel : testObject) {
                stringBuilder.append(rfbDataModel);
                stringBuilder.append(";");
            }
            return stringBuilder.toString();
        }
        return "";
    }

    /**
     * 获取发起时间
     * @return
     */
    public String obtainStartTimeStr(){
        SimpleDateFormat simpleDateFormat = new SimpleDateFormat(ConstData.TIME_FORMAT_YYYY_MM_DD);
        return simpleDateFormat.format(new Date(startTime));
    }

    /**
     * 获取结束时间
     * @return
     */
    public String obtainStopTimeStr(){
        if (0 != stopTime) {
            SimpleDateFormat simpleDateFormat = new SimpleDateFormat(ConstData.TIME_FORMAT_YYYY_MM_DD);
            return simpleDateFormat.format(new Date(stopTime));
        }
        return "-";
    }


    /**
     * 获取状态
     * @return
     */
    public String obtainProjectStatusStr(){
        if (!StringUtils.isEmpty(projectStatus)) {
            switch (projectStatus) {
                case "0":
                    return "未开始";
                case "1":
                    return "进行中";
                default:
                    return "已完成";
            }
        }
        return "-";
    }

    /**
     * 获取完成时间
     * @return
     */
    public String obtainCompleteTimeStr(){
        if (0 != completeTime) {
            SimpleDateFormat simpleDateFormat = new SimpleDateFormat(ConstData.TIME_FORMAT_YYYY_MM_DD);
            return simpleDateFormat.format(new Date(completeTime));
        }
        return "-";
    }

    public String getStartPersonStr(){
        return "本机";
    }



}
